package com.park.web.controller.user;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.park.client.model.user.IntegralConsumeModel;
import com.park.client.model.user.IntegralIncomeModel;
import com.park.client.service.user.IntegralConsumeService;
import com.park.client.service.user.IntegralIncomeService;
import com.park.common.util.Page;
import com.park.web.contant.Global;
import com.park.web.controller.BaseController;
import com.park.web.util.SessionUtil;

/**
 * @author Administrator
 *积分管理
 */
@Controller
@RequestMapping("/user/integral")
public class UserIntegralController extends BaseController{
	@Autowired
	private IntegralConsumeService consumeService;
	@Autowired
	private IntegralIncomeService incomeService;
	/**
	 *积分管理页面
	 */
	@RequestMapping("integralManage")
	public String integralManage(){
		return Global.USER_PATH+"integral/integralManage";
	}
	
	/**
	 * 消费记录
	 * @param pageNow
	 * @param request
	 * @param session
	 * @return
	 */
	@RequestMapping("consumeRecord")
	public String consumeRecord(Integer pageNow,HttpServletRequest request,HttpSession session){
		IntegralConsumeModel consume = new IntegralConsumeModel();
		consume.setUserId(SessionUtil.getUserID(session));
		Integer total = consumeService.selectTotal(consume);
		Page page = new Page(pageNow,total,10);
		consume.setStartPos(page.getStartPos());
		consume.setPageSize(page.getPageSize());
		List<IntegralConsumeModel> integralConsumes  = consumeService.selectPagination(consume);
		request.setAttribute("total", total);
		request.setAttribute("page", page);
		request.setAttribute("integralConsumes", integralConsumes);
		return Global.USER_PATH+"integral/integralRecord";
	}
	
	/**
	 * 消费站内收入
	 * @param pageNow
	 * @param request
	 * @param session
	 * @return
	 */
	@RequestMapping("integralIncome")
	public String integralIncome(Integer pageNow,HttpServletRequest request,HttpSession session){
		IntegralIncomeModel income = new IntegralIncomeModel();
		income.setUserId(SessionUtil.getUserID(session));
		Integer total = incomeService.selectTotal(income);
		Page page = new Page(pageNow,total,10);
		income.setStartPos(page.getStartPos());
		income.setPageSize(page.getPageSize());
		List<IntegralIncomeModel> integralIncomes  = incomeService.selectPagination(income);
		request.setAttribute("total", total);
		request.setAttribute("page", page);
		request.setAttribute("integralIncomes", integralIncomes);
		return Global.USER_PATH+"integral/integralIncome";
	}
	
	
}
